import VueRouter from 'vue-router'
import NProgress from 'nprogress'
import store from '@/store/store'
import util from '@/libs/util';

let { cookies } = util


//路由配置
import { routeMapBase } from './routeMapBase.js'
import { routeMapMain } from './routeMapMain.js'
import { routeMapGames } from './routeMapGames.js' //这个不能删掉，旧的分享是这个页面
import { routeMapUc } from './routeMapUc.js'


// 关于路由name警告：https://blog.csdn.net/weixin_39015132/article/details/83614689

//生成路由对象
const router = new VueRouter({

	//释放路由配置
	routes: [
		...routeMapMain,
		...routeMapBase,
		...routeMapUc,
		...routeMapGames
	],

	//滚动行为，切换路由时，会回到顶部，不会在原位
	scrollBehavior (to, from, savedPosition) {
		//todo 赛事页面页面开发完成后，可能要适配这里的数据
		let _toBeScrollTopRoute = ['contestHall','contest']
		if(_toBeScrollTopRoute.includes(to.name)){
			//什么都不写会保持原来的滚动高度
			return { x: 0, y: 0 }
		}else{
			return { x: 0, y: 0 }
		}

	}
})


// 路由勾子必须挂在new后的实例上
router.beforeEach((to, from, next) => {
	NProgress.start()
	next();//这个回调方法一定要执行，路由最终才能跳转
	NProgress.done();
})

// 路由勾子必须挂在new后的实例上
router.afterEach((to, after) => {
	NProgress.done()

})


export default router